/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Threads;

import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.URL;
import javax.imageio.ImageIO;

/**
 *
 * @author QuangHau
 */
public class downLoadImage extends Thread{
    String url;
    String name;
    public downLoadImage(String _url, int _id) {
        url = _url;
        name = _id +".jpg";
    }
    
    @Override
    public void run() {
        try {
            BufferedImage image = ImageIO.read(new URL(url));
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            ImageIO.write(image, "jpg", baos);
            FileOutputStream fout = new FileOutputStream("Image\\" + name);
            fout.write(baos.toByteArray());
            fout.close();
        } catch (IOException e) {
        }
    }
}
